package com.dji.sdk.self.internal.network;

import com.dji.sdk.self.internal.model.Urls;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtil {
    private volatile static RetrofitUtil sInstance;
    private Retrofit retrofit;
    private Api api;
    private RetrofitUtil(){
        retrofit = new Retrofit.Builder()
                .baseUrl(Urls.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        api = retrofit.create(Api.class);
    }
    public static RetrofitUtil getInstance(){
        if(sInstance == null){
            synchronized (RetrofitUtil.class){
                if(sInstance == null){
                    sInstance = new RetrofitUtil();
                }
            }
        }
        return  sInstance;
    }

    public Api getApi(){
        return api;
    }
}
